﻿#include"SList.h"

int test01()
{
	// 创建链表
	SLTNode* node1 = (SLTNode*)malloc(sizeof(SLTNode));
	SLTNode* node2 = (SLTNode*)malloc(sizeof(SLTNode));
	SLTNode* node3 = (SLTNode*)malloc(sizeof(SLTNode));
	SLTNode* node4 = (SLTNode*)malloc(sizeof(SLTNode));

	node1->data = 1;
	node2->data = 2;
	node3->data = 3;
	node4->data = 4;

	node1->next = node2;
	node2->next = node3;
	node3->next = node4;
	node4->next = NULL;
	//打印链表
	SLTNode* plist = node1;
	SLTPrint(plist);
}

void test02()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);
}

void test03()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPrint(plist);
	SLTPushFront(&plist, 2);
	SLTPrint(plist);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);
	SLTPushFront(&plist, 4);
	SLTPrint(plist);
}

void test04()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	SLTPopBack(&plist);
	SLTPrint(plist);
	SLTPopBack(&plist);
	SLTPrint(plist);
	SLTPopBack(&plist);
	SLTPrint(plist);

	SLTPopBack(&plist);
	SLTPrint(plist);
}

void test05()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	//头删
	SLTPopFront(&plist);
	SLTPrint(plist);
	SLTPopFront(&plist);
	SLTPrint(plist);
	SLTPopFront(&plist);
	SLTPrint(plist);
	SLTPopFront(&plist);
	SLTPrint(plist);

}

void test06()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);
	SLTNode* pos = SLTFind(plist, 3); //为什么是SLTNode*呢？因为SLTFinde返回的是节点的地址
	if (pos)
	{
		printf("找到了");
	}
	else
	{
		printf("未找到");
	}
}

void test07()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	//在指定位置之前插入数据
	SLTNode* pos = SLTFind(plist, 1);
	SLTInsert(&plist, pos, 100);
	SLTPrint(plist);
}
void test08()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	//在指定位置之后插入数据
	SLTNode* pos = SLTFind(plist, 2);
	SLTInsertAfter(pos, 100);
	SLTPrint(plist);
	
}

void test09()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	//在指定位置之后插入数据
	SLTNode* pos = SLTFind(plist, 4);
	SLTErase(&plist, pos);
	SLTPrint(plist);

}
void test10()
{
	//创建空链表
	SLTNode* plist = NULL;
	SLTPushBack(&plist, 1);
	SLTPushBack(&plist, 2);
	SLTPushBack(&plist, 3);
	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	//在指定位置之后插入数据
	SLTNode* pos = SLTFind(plist, 3);
	SLTEraseAfter(pos);
	SLTPrint(plist);

	SListDestroy(&plist);
	//销毁链表
	SLTPrint(plist);
}

int main()
{
	test01();
	//test02();
	//test03();
	//test04();
	//test05();
	//test06();
	//test09();
	//test10();
	return 0;
}